package cn.xkai.exercise.b;

/**
 * @description: 目标和
 * @author: kaixiang
 * @date: 2022-07-21
 **/
public class Solution82 {
    private int count = 0;

    public int findTargetSumWays(int[] nums, int S) {
        dfs(nums, 0, S, 0);
        return count;
    }

    public void dfs(int[] nums, int index, int target, int current) {
        if (index == nums.length) {
            if (target == current) {
                count++;
            }
            return;
        }

        dfs(nums, index + 1, target, current + nums[index]);
        dfs(nums, index + 1, target, current - nums[index]);
    }
}
